//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pt;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.dao.wills.PtBespeakDao;
import com.aidong.dao.wills.PtCoachCodeDao;
import com.aidong.dao.wills.PtContractDao;
import com.aidong.model.wills.PtBespeak;
import com.aidong.service.SmsListService;
import com.aidong.web.controller.BaseController;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"ptBespeakClear"})
public class PtBespeakClearController extends BaseController {
    @Resource
    PtBespeakDao ptBespeakDao;
    @Resource
    PtContractDao ptContractDao;
    @Resource
    PtCoachCodeDao ptCoachCodeDao;
    @Resource
    MemberInfoDao memberInfoDao;
    @Resource
    SmsListService smsListService;

    public PtBespeakClearController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list(@RequestParam(value = "tp",required = false) String tp) {
        return (new ModelAndView("pt/bespeakclear/list")).addObject("tp", tp);
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "coachCode",required = false) String coachCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "tp",required = false) String tp, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "b.shopCode", shopCode);
        cd.eq("b.memberCode", memberCode);
        cd.eq("m.cardCode", cardCode);
        cd.eq("coachCode", coachCode);
        cd.in("b.status", new Object[]{Integer.valueOf(2), Integer.valueOf(3)});
        if(!this.chkNull(dateFrom)) {
            cd.ge("classTime", this.parseDate(dateFrom, "yyyy-MM-dd"));
        }

        if(!this.chkNull(dateTo)) {
            cd.le("classTime", this.parseDate(dateTo + " 23:59:59", "yyyy-MM-dd HH:mm:ss"));
        }

        this.ptBespeakDao.queryPageList(pg, cd);
        ModelAndView mv = new ModelAndView("pt/bespeakclear/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        mv.addObject("tp", tp);
        mv.addObject("date0", new Date());
        return mv;
    }

    @RequestMapping({"_clear"})
    @ResponseBody
    public String _clear(@RequestParam("id") String ids) {
        String[] ss = ids.split(",");
        ArrayList list = new ArrayList();
        String[] bespeak = ss;
        int e = ss.length;
        int b = 0;

        while(true) {
            if(b < e) {
                String s = bespeak[b];
                Integer id = this.parseInt(s);
                if(this.chkNullZ(id)) {
                    return this.getResult(false, "数据错误");
                }

                PtBespeak bespeak1 = (PtBespeak)this.ptBespeakDao.getById(id);
                if(bespeak1 != null && bespeak1.getStatus().intValue() != 0) {
                    if(bespeak1.getStatus().intValue() == 1) {
                        return this.getResult(false, "已经核销");
                    }

                    if(bespeak1.getStatus().intValue() != 2 && bespeak1.getStatus().intValue() != 3) {
                        return this.getResult(false, "不能核销");
                    }

                    if(bespeak1.getPrintLabel().intValue() != 1 && bespeak1.getStatus().intValue() != 3) {
                        return this.getResult(false, "没有打印小票,不能核销");
                    }

                    bespeak1.setStatus(Integer.valueOf(1));
                    bespeak1.setClearUser(this.getLoginUserCode());
                    bespeak1.setClearTime(new Date());
                    list.add(bespeak1);
                    ++b;
                    continue;
                }

                return this.getResult(false, "没有这个预约");
            }

            if(list.size() == 0) {
                return this.getResult(false, "...");
            }

            PtBespeak var11 = (PtBespeak)list.get(0);

            try {
                this.ptBespeakDao.updateClear(list);
                Iterator var12 = list.iterator();

                while(var12.hasNext()) {
                    PtBespeak var13 = (PtBespeak)var12.next();
                    this.smsListService.addSmsList("23", var13.getAutoId().intValue());
                }

                this.addUserLog("预约核销", "流水号:" + var11.getAutoId() + ",合同号:" + var11.getContractCode() + ",会员号:" + var11.getMemberCode());
                return this.getResult(true, "核销成功");
            } catch (Exception var10) {
                this.log.error("ptbespeak clear", var10);
                return this.getResult(false, "核销发生错误");
            }
        }
    }
}
